#pragma once
#include "ControlBase.h"

class Label : public Control
{
public:
	float last_width = 0.0f;
	virtual UIClass Type() { return UIClass::UI_Label; }
	bool IsContainer() override
	{
		return false;
	}
	Label(std::wstring text, int x, int y)
	{
		this->Text = text;
		this->Location = POINT{x, y};
		this->BackColor = D2D1_COLOR_F{.0f, .0f, .0f, .0f};
	}
	SIZE ActualSize() override
	{
		auto d2d = this->Render;
		auto font = this->Font ? this->Font : d2d->DefaultFontObject;
		auto text_size = font->GetTextSize(this->Text);
		return SIZE{(int)text_size.width, (int)text_size.height};
	}
	void Update() override
	{
		if (this->IsVisual == false)
			return;
		auto d2d = this->Render;
		auto abslocation = this->AbsLocation;
		auto size = this->ActualSize();
		auto absRect = this->AbsRect;
		if (last_width > size.cx)
		{
			absRect.right += last_width - size.cx;
			size.cx = last_width;
		}
		d2d->PushDrawRect(absRect.left, absRect.top, absRect.right - absRect.left, absRect.bottom - absRect.top);
		{
			d2d->FillRect(abslocation.x, abslocation.y, size.cx, size.cy, this->Parent->BackColor);
			if (this->Parent->Image)
			{
				this->Parent->RenderImage();
			}
			if (this->Image)
			{
				this->RenderImage();
			}
			d2d->DrawString(this->Text, abslocation.x, abslocation.y, this->ForeColor, this->Font);
		}
		d2d->PopDrawRect();
		last_width = size.cx;
	}
};